<template>
	<view class="content">
		<button @click="goTo" style="margin: 10px auto;width: 50%;" type="primary">发朋友圈</button>
		<friendcenter @delFri='dele(item.friendId)' v-for="item in friendquan" :uavatar='item.avatar' :uname='item.userName' :content1='item.title' :pics='item.contentPic'></friendcenter>
		<uni-popup type="dialog" ref="delDialog">
			<uni-popup-dialog style='flex-direction: column;' ref="pop1"  title="确认删除朋友圈吗？" 
			 @confirm="delConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {queryQuan,delQuan} from '../../service/index.js'
	import friendcenter from '../../components/friendcenter/friendcenter.vue'
	export default {
		
		data() {
			return {
				friendquan:[]
			}
		},
		onLoad() {
			//加载朋友圈列表
			this.showList()
		},
		methods: {
			goTo(){
				uni.navigateTo({
					url:'/pages/createFC/createFC'
				})
			},
			//加载朋友圈列表
			async showList(){
				let data=await queryQuan()
				//console.log(data);
				data.data.forEach(v=>{
					v.contentPic=v.contentPic.split(',')//照片字符串转数组
				})
				//console.log(data.data)
				this.friendquan=data.data
				
				//console.log(this.friendquan);
			},
			// 删除朋友圈
			dele(id){
				//console.log(id)
				uni.setStorageSync('momentsId',id)
				this.$refs.delDialog.open('center')
			},
			async delConfirm(){
				let mid=uni.getStorageSync('momentsId')
				let data=await delQuan(mid)
				console.log(data);
				if(data.code==200){
					//加载朋友圈列表
					this.showList()
					uni.showToast({
						title:'删除成功',
						icon:'success',
						duration:2000
					})
				}
			}
		}
	}
</script>

<style>

</style>
